
#方法一，设置共有类
# class Payment:
#     def pay(self,money):
#         raise NotImplementedError

#方法二，设置抽象类,常用
from abc import ABCMeta,abstractmethod

class Payment(metaclass=ABCMeta):
    #abstract class
    @abstractmethod
    def pay(self,money):
        pass

class Alipay(Payment):
    def pay(self,money):
        print("支付宝支付%d元"%money)

class WechatPay(Payment):
    def pay(self,money):
        print("微信支付%d元"%money)

p=Alipay()
p.pay(100)

class BankPay:
    def cost(self,money):
        print("银联支付%d元"%money)

class ApplePay:
    def cost(self,money):
        print("苹果支付%d元"%money)

#类适配器
class NewBankPay(Payment,BankPay):
    def pay(self,money):
        self.cost(money)

#对象适配器，组合，在一个类里放入另外一个类的对象
class PaymentAdapter(Payment):
    def __init__(self,payment):
        self.payment=payment

    def pay(self,money):
        self.payment.cost(money)

class User:
    def show_name(self):
        pass
class VIPUser(User):
    def show_name(self):
        pass
def show_user(u):
    res=u.show_name()


class LandAnimal(metaclass=ABCMeta):
    @abstractmethod
    def walk(self):
        pass
class WaterAnimal(metaclass=ABCMeta):
    @abstractmethod
    def swim(self):
        pass
class SkyAnimal(metaclass=ABCMeta):
    @abstractmethod
    def fly(self):
        pass

class Tiger(LandAnimal):
    def walk(self):
        print("老虎走路")
class Frog(LandAnimal,WaterAnimal):
    def walk(self):
        print("青蛙走路")
    def swim(self):
        print("青蛙游泳")

p=PaymentAdapter(ApplePay())
p.pay(100)